<?php

namespace App\Admin\Controllers\Log;

use App\Admin\Repositories\Log\LogUserPay;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class LogUserPayController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new LogUserPay(), function (Grid $grid) {
            $grid->model()->orderby('id', 'desc');
            $grid->column('id')->sortable();
            $grid->column('uid')->sortable();
            $grid->column('user_identity', '会员昵称')->display(function () {
                return isset($this->user->nickname) ? $this->user->nickname : "-";
            });
            $grid->column('order_no');
            $grid->column('type')->display(function () {
                return "微信";
            });
            $grid->column('money');
            $grid->column('status')->using(['1' => '未支付', '2' => '已支付', '3' => '已取消'])->label([
                1 => 'danger',
                2 => 'success',
                3 => 'primary',
            ]);
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->equal('uid', '会员id');
                $filter->like('user.nickname', '会员昵称');
            });
            $grid->export();
            $grid->disableDeleteButton();
            $grid->disableEditButton();
            $grid->disableCreateButton();
            $grid->disableRowSelector();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new LogUserPay(), function (Show $show) {
            $show->field('id');
            $show->field('uid');
            $show->field('order_no');
            $show->field('type');
            $show->field('order_type');
            $show->field('money');
            $show->field('platform');
            $show->field('status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new LogUserPay(), function (Form $form) {
            $form->display('id');
            $form->text('uid');
            $form->text('order_no');
            $form->text('type');
            $form->text('order_type');
            $form->text('money');
            $form->text('platform');
            $form->text('status');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
